package dao;

import java.util.List;

import javax.persistence.Query;

import model.Book;
import model.Category;

import org.apache.log4j.Logger;

public class CategoryDao extends AbstractDao<Category> {

	public static Logger log =Logger.getLogger(CategoryDao.class);
	
	@SuppressWarnings("unchecked")
	public List<Book> getCategoryBooksById(String id) {
		Long selectId = new Long(id);
		log.info("Recherche des books de la cat�gorie " + id);
		Query query = getEm().createQuery("from Book b where b.category.id = :id");
		query.setParameter("id", selectId);
		List<Book> books = query.getResultList();
		return books;
	}

	@SuppressWarnings("unchecked")
	public List<model.Category> getCategories() {
		log.info("Rechercher toutes les cat�gories");
		Query query = getEm().createQuery("from Category");
		List<model.Category> categories = query.getResultList();
		return categories;
	}

}
